package com.chen.pojo;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.chen.pojo.bean.UserInfo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


import java.util.Date;


@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("user")
@SuppressWarnings("all")
@ApiModel

/**
 * 用户表
 */
public class User {
    /**
     * 主键id
     */
    @TableId(type = IdType.AUTO) //设置自增
    private Integer id;

    /**
     * 用户名
     */
    @ApiModelProperty("用户名")
    private String username;

    /**
     * 密码
     */
    @ApiModelProperty("密码")

    private String password;

    /**
     * 昵称
     */
    private String nick;

    /**
     * 性别
     */
    private String sex;
    /**
     * 住址
     */
    private String address;

    /**
     * 年龄
     */

    private int age;

    /**
     * 头像
     */
    private String avatar;

    /**
     * 注册时间
     */
    private Date regtime;

    /**
     * 角色 1：管理员 2：普通用户
     */
    private int role;

    /**
     * 状态 1：已审核 2：未审核
     */
    private int status;

    /**
     * 介绍
     */
    private String introduce;

    @TableField(exist = false)
    private int count;

//    注册的人数
    @TableField(exist = false)
    private int total;

//    注册时间
    @TableField(exist = false)
    private String time;


    public User(UserInfo info) {
        this.id = info.getId();
        this.username = info.getUsername();
        this.nick = info.getNick();
        this.sex = info.getSex();
        this.address = info.getAddress();
        this.age = info.getAge();
        this.avatar = info.getAvatar();
        try {
            this.regtime = DateUtil.parse(info.getRegtime(),"yyyy-MM-dd HH:mm:ss");
        } catch (Exception e) {
            this.regtime = new Date();
        }
        this.role = info.getRole();
        this.status = info.getStatus();
        this.introduce = info.getIntroduce();
    }
}
